package com.example.hybridmobiledemo.view;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.hybridmobiledemo.R;
import com.example.hybridmobiledemo.module.main.model.hospital.RecommendDoctor;
import com.example.hybridmobiledemo.module.main.model.hospital.bean.Registering;

import java.util.List;

public class MedicalAdapter extends RecyclerView.Adapter<MedicalAdapter.ViewHolder> {
    private List<Registering> list;
    private Context context;

    public MedicalAdapter(Context context, List<Registering> list){
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.medical_item,parent,false);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Registering registering  = list.get(position);
        holder.item_number.setText(registering.getNumber());
        holder.item_hospital.setText(registering.getHospital());
        holder.item_section.setText(registering.getSection());
        holder.item_OPC.setText(registering.getOPC());
        holder.item_operation.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.startActivity(new Intent(context, RecommendDoctor.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        if(list != null){
            return list.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView item_number,item_hospital,item_section,item_OPC, item_operation;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item_number = itemView.findViewById(R.id.item_number);
            item_hospital = itemView.findViewById(R.id.item_hospital);
            item_section = itemView.findViewById(R.id.item_section);
            item_OPC = itemView.findViewById(R.id.item_OPC);
            item_operation = itemView.findViewById(R.id.item_operation);
        }
    }
}
